package appconfig

import (
	"fmt"
	"github.com/spf13/viper"
)

type AppConfig struct {
	Mysql
	Redis
	Jwt
	QiNiu
	HuYi
	Tencent
}

type Mysql struct {
	Username string
	Password string
	Host     string
	Port     int
	Database string
}
type Redis struct {
	Addr string
	DB   int
}

type Jwt struct {
	AccessSecret string
	ExpireTime   int64
}

type QiNiu struct {
	AccessKey string
	SecretKey string
	Buckets   string
	Host      string
}

type HuYi struct {
	APIId  string
	APIKEY string
}

type Tencent struct {
	SecretId  string
	SecretKey string
}

var AppConf AppConfig

func LoadConfig() {
	viper.SetConfigFile("../appconfig/dev.yaml")
	err := viper.ReadInConfig()
	if err != nil {
		fmt.Printf("配置文件读取失败err: %v\n", err)
		return
	}
	err = viper.Unmarshal(&AppConf)
	if err != nil {
		fmt.Println("配置文件解析失败")
		return
	}
	fmt.Println(AppConf)
}
